//
//  MyStockOpinionCenter.m
//  Stock
//
//  Created by blacksun on 11-9-28.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "MyStockOpinionCenter.h"
#import "JWRateStarView.h"

@implementation MyStockOpinionCenter
@synthesize starContainer;


#pragma mark -Service Delegate
-(void)requestFinishedWithResult:(id)aResult andUserinfo:(NSDictionary *)aUserinfo{
    NSString *action = [aUserinfo objectForKey:kASIHttpRequestUserinfoKey];
    if ([action isEqualToString:kMyStokcServiceQueryOpinionDetail]) {
        label1.text = [NSString stringWithFormat:@"%d",[[aResult objectForKey:@"weekRank"] intValue]];
        label4.text = [NSString stringWithFormat:@"%d",[[aResult objectForKey:@"monthRank"] intValue]];
        label2.text = [NSString stringWithFormat:@"%d",abs([[aResult objectForKey:@"weekRankGrowth"] intValue])];
        label5.text = [NSString stringWithFormat:@"%d",abs([[aResult objectForKey:@"monthRankGrowth"] intValue])];
        
        if ([[aResult objectForKey:@"weekRankGrowth"] intValue]>0) {
            imageView.image = [UIImage imageNamed:@"icon_up.png"];
        }else if([[aResult objectForKey:@"weekRankGrowth"] intValue]<0){
            imageView.image = [UIImage imageNamed:@"icon_down_green.png"];
        }else{
            imageView.image = nil;
            label2.text = @"—";
        }
        
        
        if ([[aResult objectForKey:@"monthRankGrowth"] intValue]>0) {
            selectedImage.image = [UIImage imageNamed:@"icon_up.png"];
        }else if([[aResult objectForKey:@"monthRankGrowth"] intValue]<0){
            selectedImage.image = [UIImage imageNamed:@"icon_down_green.png"];
        }else{
            selectedImage.image = nil;
            label5.text = @"—";
        }
        
        label3.text = [NSString stringWithFormat:@"%0.1f-%0.1f          %@",[[aResult objectForKey:@"weekLowPrice"] floatValue],[[aResult objectForKey:@"weekHighPrice"] floatValue],[aResult objectForKey:@"weekPriceRange"]];
        label6.text = [NSString stringWithFormat:@"%0.1f-%0.1f          %@",[[aResult objectForKey:@"monthLowPrice"] floatValue],[[aResult objectForKey:@"monthHighPrice"] floatValue],[aResult objectForKey:@"monthPriceRange"]];
        
        float grade = [[aResult objectForKey:@"grade"] floatValue];
        JWRateStarView *starView = (JWRateStarView *)self.starContainer;
        starView.totalStarCount = 5;
        [starView setRate:grade];
    }
}


-(void)reloadViews{
    
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.pubDateLabel.text = [[[StockContext shareInstance].updateTimes objectAtIndex:2] objectForKey:@"time"];
}
-(void)setupSelf{
   
    [self.myStockService queryStockOpinionCenterDetailWithStockId:myStock.uuid];
    
    /*OpinionTrendController *trendController = [[OpinionTrendController alloc] initWithNibName:@"OpinionTrendController" bundle:nil];
    trendController.stockId = myStock.uuid;
    trendController.view.frame = CGRectMake(0.0, 250.0, 320.0, 120.0);
    [self.view addSubview:trendController.view];
    [childViewControllers addObject:trendController];
    [trendController release];*/
    
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(void)dealloc{
    self.starContainer = nil;
    [super dealloc];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
